﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using InkFx.WinControl.Core;

namespace Temp_20190707_AForm
{
    public class SplitterForm : Form
    {
        //protected override CreateParams CreateParams
        //{
        //    get
        //    {
        //        CreateParams createParams = base.CreateParams;
        //        createParams.ExStyle |= (int)WindowStyleEx.WS_EX_TOOLWINDOW;
        //        return createParams;
        //    }
        //}
        public SplitterForm(Rectangle rect)
        {
            //base.DoubleBuffered = true; //这种需要快速弹出的窗体, 设置 双缓冲 只会减慢启动速度
            base.ShowInTaskbar = false;
            base.FormBorderStyle = FormBorderStyle.None;
            base.TransparencyKey = Win32API.Transparent;
            base.BackColor = Color.White; //Win32API.Transparent; //
            base.StartPosition = FormStartPosition.Manual;
            base.Bounds = rect;
            //base.Opacity = 0.5;
            base.SetStyle(ControlStyles.Selectable, false);
            base.Enabled = false;
        }

        public static SplitterForm BeginSplitter(Rectangle rect)
        {
            SplitterForm form = new SplitterForm(rect);
            Win32API.ShowWindow(form.Handle, 4);
            return form;
        }

        public void ShowSplitter(Rectangle rect)
        {
            this.Bounds = rect;
        }
        public void EndSplitter()
        {
            this.Close();
            this.Dispose();
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == Win32Msg.WM_NCHITTEST)
            {
                m.Result = (IntPtr)(-1L);
                return;
            }
            base.WndProc(ref m);
        }


        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            base.DoubleBuffered = true;
        }
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
            //Win32API.DrawSplitHelper(this.Handle, new Rectangle(0, 0, this.Width, this.Height));
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //e.Graphics.Clear(Color.PaleVioletRed);
            //Win32API.DrawSplitHelper(this.Handle, new Rectangle(0, 0, this.Width, this.Height));
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            //Win32API.DrawSplitHelper(this.Handle, new Rectangle(0, 0, this.Width, this.Height));
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            //Win32API.DrawSplitHelper(this.Handle, new Rectangle(0, 0, this.Width, this.Height));
        }

    }
}
